import request from '@/utils/request'
import { otherFiltersItem } from '@/utils'
/**
 * 新增
 * @param {object} data
 * @returns
 */
export function postShopDecoration(data) {
  return request({
    url: '/api/v1/shopDecoration',
    method: 'post',
    data
  })
}
/**
 * 修改
 * @param {object} data
 * @returns
 */
export function putShopDecoration(data) {
  return request({
    url: '/api/v1/shopDecoration',
    method: 'put',
    data
  })
}
/**
 * 获取所有
 * @returns array
 */
export function getShopDecoration() {
  return request({
    url: '/api/v1/shopDecoration/',
    method: 'get'
  })
}
/**
 * 根据id查询
 * @param {string} id
 * @returns
 */
export function getShopDecorationById(id) {
  return request({
    url: `/api/v1/shopDecoration/${id}`,
    method: 'get'
  })
}
/**
 * 根据id删除
 * @param {string} id
 * @returns
 */
export function deleteShopDecorationById(id) {
  return request({
    url: `/api/v1/shopDecoration/${id}`,
    method: 'delete'
  })
}
/**
 * 编辑或新增
 * @param {object} data
 * @returns
 */
export function postAddOrEdit(data) {
  return request({
    url: `/api/v1/shopDecoration/addOrEdit`,
    method: 'post',
    data
  })
}
/**
 * 手动新增装修任务
 * @param {object}} data
 * @returns
 */
export function postAddTask(data) {
  return request({
    url: `/api/v1/shopDecoration/addTask`,
    method: 'post',
    data
  })
}
/**
 * 资料审核
 * @param {object} data
 * @returns
 */
export function postAudit(data) {
  return request({
    url: `/api/v1/shopDecoration/audit`,
    method: 'post',
    data
  })
}
/**
 * 委派施工单位
 * @param {object} data
 * @returns
 */
export function postBatchCreateUnit(data) {
  return request({
    url: `/api/v1/shopDecoration/batchCreateUnit`,
    method: 'post',
    data
  })
}
/**
 * 修改状态
 * @param {string} id
 * @param {number} state
 * @returns
 */
export function getChangeStateById(id, state) {
  return request({
    url: `/api/v1/shopDecoration/changeState/${id}/${state}`,
    method: 'get'
  })
}

/**
 * 确认施工单位
 * @param {object} data
 * @returns
 */
export function postConfirmUnit(data) {
  return request({
    url: `/api/v1/shopDecoration/confirmUnit`,
    method: 'post',
    data
  })
}
/**
 * 任务处理
 * @param {object} data
 * @returns
 */
export function postDealPro(data) {
  return request({
    url: `/api/v1/shopDecoration/dealPro`,
    method: 'post',
    data
  })
}
/**
 * 延期进场
 * @param {object} data
 * @returns
 */
export function postDelayIn(data) {
  return request({
    url: `/api/v1/shopDecoration/delayIn`,
    method: 'post',
    data
  })
}
/**
 * 延期
 * @param {object} data
 * @returns
 */
export function putDelayIn(data) {
  return request({
    url: `/api/v1/shopDecoration/delayPro`,
    method: 'put',
    data
  })
}
/**
 * 批量删除
 * @param {array} data
 * @returns
 */
export function deleteBatch(data) {
  return request({
    url: `/api/v1/shopDecoration/deleteBatch`,
    method: 'delete',
    data
  })
}
/**
 * 批量终止任务
 * @param {array} data
 * @returns
 */
export function putEndPro(data) {
  return request({
    url: `/api/v1/shopDecoration/endPro`,
    method: 'put',
    data
  })
}
/**
 * 装修执行/发起异常
 * @param {object} data
 * @returns
 */
export function postSendException(data) {
  return request({
    url: `/api/v1/shopDecoration/execute/SendException`,
    method: 'post',
    data
  })
}
/**
 * 装修完工
 * @param {object} data
 * @returns
 */
export function postFinish(data) {
  return request({
    url: `/api/v1/shopDecoration/finish`,
    method: 'post',
    data
  })
}
/**
 * 根据id查询，多表联查
 * @param {string} id
 * @returns
 */
export function getGetOneByid(id) {
  return request({
    url: `/api/v1/shopDecoration/getOne/${id}`,
    method: 'get'
  })
}
/**
 * 查询卖场和门头的总设计面积
 * @param {string} id
 * @returns
 */
export function getGetTotalAreaByid(id) {
  return request({
    url: `/api/v1/shopDecoration/getTotalArea/${id}`,
    method: 'get'
  })
}
/**
 * 新增关联图纸
 * @param {object} data
 * @returns
 */
export function postInsertPic(data) {
  return request({
    url: `/api/v1/shopDecoration/insertPic`,
    method: 'post',
    data
  })
}
/**
 * 进场
 * @param {object} data
 * @returns
 */
export function postInside(data) {
  return request({
    url: `/api/v1/shopDecoration/inside`,
    method: 'post',
    data
  })
}
/**
 * 作废任务
 * @param {object} data
 * @returns
 */
export function postInvalidPro(data) {
  return request({
    url: `/api/v1/shopDecoration/invalidPro`,
    method: 'post',
    data
  })
}
/**
 * 逻辑删除
 * @param {string} id
 * @returns
 */
export function deleteLogicDeleteById(id) {
  return request({
    url: `/api/v1/shopDecoration/logicDelete/${id}`,
    method: 'delete'
  })
}
/**
 * 项目启动会召开
 * @param {object} id
 * @returns
 */
export function postMeeting(data) {
  return request({
    url: `/api/v1/shopDecoration/meeting`,
    method: 'post',
    data
  })
}
/**
 * 根据验收id查询装修数据
 * @param {string} accId
 * @returns
 */
export function getSelectByAccId(accId) {
  return request({
    url: `/api/v1/shopDecoration/selectByAccId/${accId}`,
    method: 'get'
  })
}
/**
 * 安排工程监理
 * @param {object} data
 * @returns
 */
export function postSetSupervisor(data, reqType) {
  return request({
    url: `/api/v1/shopDecoration/setSupervisor/${reqType}`,
    method: 'post',
    data
  })
}
/**
 * 隐蔽工程验收、复尺、初检
 * @param {object} data
 * @returns
 */
export function postTriad(data) {
  return request({
    url: `/api/v1/shopDecoration/triad`,
    method: 'post',
    data
  })
}

/**
 * 施工单位评分
 * @param {*} data
 * @returns
 */
export function postConstUnitAssessScoreDetail(decorationTaskCode, unitCode, ids) {
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify([
    otherFiltersItem('decorationTaskCode', decorationTaskCode, '='),
    otherFiltersItem('unitCode', unitCode, '='),
    otherFiltersItem('scoreCriteriaId', `[${ids.join(',')}]`, '=')
  ]))
  return request({
    url: `/api/v1/constUnitAssessScore/detail`,
    method: 'post',
    data
  })
}
/**
 * 获取当前委派批次号
 * @param {string} decorationTaskCode
 * @returns
 */
export function postGetMaxBatch(decorationTaskCode) {
  return request({
    url: `/api/v1/decorationDelegateDetail/getMaxBatch/${decorationTaskCode}`,
    method: 'POST'
  })
}
/**
 * 根据装修任务号批量获取委派批次
 * @param {*} data
 * @returns
 */
export function getDetailBatch(data) {
  return request({
    url: '/api/v1/decorationDelegateDetail/getDetailBatch',
    method: 'POST',
    data
  })
}
/**
 * 发起异常
 * @param {*} data
 * @returns
 */
export function postShopException(data) {
  return request({
    url: `/api/v1/shopException`,
    method: 'POST',
    data
  })
}
/**
 * 获取异常类型
 * @returns
 */
export function postExceptionType(data) {
  return request({
    url: '/api/v1/configExceptionHandle/page',
    method: 'POST',
    data
  })
}
/**
 * 关联图纸
 * @param {object} data
 * @returns
 */
export function postBatchCreate(data) {
  return request({
    url: '/api/v1/modelPictureRelation/batchCreate',
    method: 'POST',
    data
  })
}
/**
 * 保存提交
 * @param {*} data
 * @returns
 */
export function postCommitPro(data) {
  return request({
    url: '/api/v1/shopDecoration/commitPro',
    method: 'POST',
    data
  })
}
/**
 *获取关联图纸
 * @param {*} data
 * @returns
 */
export function postSelectByModelId(modelId) {
  return request({
    url: `/api/v1/shopDesignPicture/selectByModelId/${modelId}`,
    method: 'get'
  })
}
/**
 * 获取委派记录
 * @param {*} decorationTaskCode
 * @returns
 */
export function postPageByTecTaskCode(decorationTaskCode) {
  const data = new FormData()
  // [otherFiltersItem('decorationTaskCode', decorationTaskCode, '=')]
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('decorationTaskCode', decorationTaskCode, '=')]))
  data.append('pageFlag', false)
  data.append('sort', 'delegateBatch')
  data.append('order', 'desc')
  return request({
    url: '/api/v1/decorationDelegateDetail/pageByTecTaskCode',
    method: 'POST',
    data
  })
}
/**
 *
 * @returns 获取考核明细配置
 */
export function postConfigScoreCriteriaPage(scoreNature) {
  if (scoreNature === undefined) {
    scoreNature = 'PRO_PROCESS'
  }
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('scoreNature', scoreNature, '=')]))
  data.append('pageFlag', false)
  return request({
    url: '/api/v1/configScoreCriteria/page',
    method: 'POST',
    data
  })
}
/**
 * 出图不装修
 * @param {*} data
 * @returns
 */
export function postUnDecWithPic(data) {
  return request({
    url: '/api/v1/shopDecoration/unDecWithPic',
    method: 'POST',
    data
  })
}
/**
 * 获取配置
 * @returns
 */
export function postConfigAttachmentTemplate() {
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('belongModel', 'SHOP_DECORATION', '=')]))
  return request({
    url: '/api/v1/configAttachmentTemplate/page',
    method: 'POST',
    data
  })
}
/**
 * 过程评分
 * @param {*} data
 * @returns
 */
export function postConstUnitAssessScore(data) {
  return request({
    url: '/api/v1/constUnitAssessScore',
    method: 'POST',
    data
  })
}
/**
 * 获取附件
 * @param {*} modelId
 * @returns
 */
export function getShopAttachment(modelId) {
  return request({
    url: `/api/v1/shopAttachment/query/${modelId}`,
    post: 'GET'
  })
}
/**
 * 删除
 * @param {*} id
 * @returns
 */
export function deleteShopAttachment(id) {
  return request({
    url: `/api/v1/shopAttachment/${id}`,
    method: 'DELETE'
  })
}
/**
 * 批量上传合同解析
 * @param {*} data
 * @returns
 */
export function postContractParsing(data) {
  return request({
    url: '/api/v1/shopDecoration/contractParsing',
    method: 'POST',
    data
  })
}
/**
 * 批量新增合同附件
 * @param {*} data
 * @returns
 */
export function postShopAttachmentBat(data) {
  return request({
    url: '/api/v1/shopAttachment/batchCreate',
    method: 'POST',
    data
  })
}
/**
 * 新增合同附件
 * @param {*} data
 * @returns
 */
export function uploadContract(data) {
  return request({
    url: `/api/v1/shopDecoration/uploadContract`,
    method: 'POST',
    data
  })
}
/**
 * 新增合同附件
 * @param {*} data
 * @returns
 */
export function postShopAttachment(data) {
  return request({
    url: '/api/v1/shopAttachment',
    method: 'POST',
    data
  })
}
/**
 * 合同变更
 * @param {*} data
 * @returns
 */
export function postChangeContract(data) {
  return request({
    url: '/api/v1/shopDecoration/changeContract',
    method: 'POST',
    data
  })
}
/**
 * 获取异常
 * @param {*} params
 * @returns
 */
export function postShopExceptionPage(modelId) {
  const data = new FormData()
  const filtersRaw = []
  filtersRaw.push(otherFiltersItem('modelId', modelId, '='))
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  return request({
    url: '/api/v1/shopException/page',
    method: 'POST',
    data
  })
}
/**
 * 委派异常
 * @param {*} data
 * @returns
 */
export function sendException(data) {
  return request({
    url: '/api/v1/shopDecoration/sendException',
    method: 'POST',
    data
  })
}
/**
 * 获取委派记录
 * @param {*} decorationTaskCode
 * @param {*} delegateBatch
 * @returns
 */
export function postUnitBydelegateBatch(decorationTaskCode, delegateBatch) {
  const data = new FormData()
  const filtersRaw = [otherFiltersItem('decorationTaskCode', decorationTaskCode, '=')]
  if (delegateBatch !== undefined) {
    filtersRaw.push(otherFiltersItem('delegateBatch', delegateBatch, '='))
  }
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  data.append('pageFlag', false)
  return request({
    url: '/api/v1/decorationDelegateDetail/pageByTecTaskCode',
    method: 'POST',
    data
  })
}
/**
 * 换一批施工单位
 * @param {array} data
 * @param {string} decorationTaskCode
 * @returns
 */
export function postAnotherUnit(data, decorationTaskCode) {
  return request({
    url: `/api/v1/shopDecoration/anotherUnit/${decorationTaskCode}`,
    method: 'post',
    data
  })
}
/**
 * 装修完工前检测数据
 * @param {*} data
 * @returns
 */
export function finishCheck(data) {
  return request({
    url: '/api/v1/shopDecoration/finishCheck',
    method: 'POST',
    data
  })
}
/**
 * 根据门店建设号获取设计详情
 * @param {*} constCode
 * @returns
 */
export function getShopDesignInfo(constCode) {
  return request({
    url: `/api/v1/shopDesign/getShopDesign/${constCode}/info`,
    method: 'GET'
  })
}

/**
 * 异常暂停
 * @param {object} data
 * @returns
 */
export function handleException(data) {
  return request({
    url: `/api/v1/shopDecoration/exceptionStop`,
    method: 'post',
    data
  })
}

/**
 * 异常恢复
 * @param {object} data
 * @returns
 */
export function resumeException(data) {
  return request({
    url: `/api/v1/shopDecoration/exceptionRestore`,
    method: 'post',
    data
  })
}
/**
 * 获取委派异常列表记录
 * @param {object} data
 * @returns
 */
export function getExpetionList(decorationId) {
  const data = new FormData()
  const filtersRaw = []
  filtersRaw.push(otherFiltersItem('decorationId', decorationId, '='))
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  return request({
    url: `/api/v1/shopDecorationUnit/page`,
    method: 'post',
    data
  })
}
